
package ui.activity.poscontrol.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.View;

import net.ck.hzq.R;

import java.util.ArrayList;
import java.util.List;

import base.BaseViewHolder;
import base.SuperBaseAdapter;
import ui.activity.order.OrderDetailsAct;
import ui.activity.poscontrol.beanmodel.PosInfoBean;


/**
 *POS查询列表适配器
 * Created by chenjian on 19/2/27
 */
public class SearchPosInfoAdapter extends SuperBaseAdapter<PosInfoBean.RecordsBean> {

    List<PosInfoBean.RecordsBean> mData = new ArrayList<>();
    Context mContext;
    int mactiveStatus = 0;
    public SearchPosInfoAdapter(Context context, List<PosInfoBean.RecordsBean> data,int activeStatus) {
        super(context, data);
        mContext = context;
        mData = data;
        mactiveStatus= activeStatus;
    }

    @Override
    protected void convert(BaseViewHolder holder, final PosInfoBean.RecordsBean item, final int position) {
        holder.setText(R.id.index, (position+1)+"")
                .setText(R.id.device_no, item.getSn())//终端编号
                .setText(R.id.rate_text, item.getRate()+"%");

        if(item.getRate().equals("0.53")){
            holder.setTextColor(R.id.device_no, Color.parseColor("#17AB28"));
        }else   if(item.getRate().equals("0.55")){
            holder.setTextColor(R.id.device_no, Color.parseColor("#F86912"));
        }else   if(item.getRate().equals("0.6")){
            holder.setTextColor(R.id.device_no, Color.parseColor("#333333"));
        }else   if(item.getRate().equals("0.65")){
            holder.setTextColor(R.id.device_no, Color.parseColor("#1232F8"));
        }else{
            holder.setTextColor(R.id.device_no, Color.parseColor("#333333"));
        }
        if(mactiveStatus ==4||mactiveStatus==5||mactiveStatus==6){
            holder.getView(R.id.arrow_image).setVisibility(View.VISIBLE);
            if(item.isSelected()){
                holder.getView(R.id.pushuser_linear).setVisibility(View.VISIBLE);
            }
            else{
                holder.getView(R.id.pushuser_linear).setVisibility(View.GONE);
            }
            holder.getView(R.id.rate_text).setVisibility(View.GONE);
        }else{
            holder.getView(R.id.rate_text).setVisibility(View.VISIBLE);
            holder.getView(R.id.arrow_image).setVisibility(View.GONE);
        }

        if(mactiveStatus ==4){
            holder.getView(R.id.date_text).setVisibility(View.VISIBLE);
            if(item.getRemainingDay()<=10){
                holder.setTextColorRes(R.id.return_usedate,R.color.red_fe3333);
            }else{
                holder.setTextColorRes(R.id.return_usedate,R.color.colorBlack);
            }
            holder.setText(R.id.return_usedate, item.getRemainingDay()+"");
            if(mData.get(position).getType() == 1){
                holder.setBackgroundResource(R.id.total_linear,R.color.blueback);
                holder.getView(R.id.return_usedate_godetail).setVisibility(View.INVISIBLE);
            }else{
                holder.setBackgroundResource(R.id.total_linear,R.color.white);
                holder.getView(R.id.return_usedate_godetail).setVisibility(View.VISIBLE);
            }
        }else{
            holder.getView(R.id.date_text).setVisibility(View.GONE);
        }

        holder.getView(R.id.date_text).setOnClickListener(v -> {
            if(mData.get(position).getType() != 1) {
                Intent intent = new Intent(mContext, OrderDetailsAct.class);
                intent.putExtra("id", item.getOrderId() + "");
                mContext.startActivity(intent);
            }
        });
        if(mactiveStatus == 6){
            holder.getView(R.id.yajinstatusitem_text).setVisibility(View.VISIBLE);
            if(item.getSign().equals("1")){
                holder.setText(R.id.yajinstatusitem_text, "已返");
            }else{
                holder.setText(R.id.yajinstatusitem_text, "冻结");
            }

        }else{
            holder.getView(R.id.yajinstatusitem_text).setVisibility(View.GONE);
        }
        holder.getView(R.id.arrow_image).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                item.setSelected(!holder.getView(R.id.arrow_image).isSelected());
                holder.getView(R.id.arrow_image).setSelected(!holder.getView(R.id.arrow_image).isSelected());
                holder.getView(R.id.pushuser_linear).setVisibility(holder.getView(R.id.arrow_image).isSelected() ? View.VISIBLE : View.GONE);
                holder.setText(R.id.name, "姓名："+item.getMerchantName())
                        .setText(R.id.phone,"电话："+ item.getMerchantPhone())//终端编号
                        .setText(R.id.rate, "费率"+item.getRate()+"%")
                        .setText(R.id.merchant_number, "商编："+item.getMerchantNo()+"");


            }
        });

    }




    @Override
    protected int getItemViewLayoutId(int position, PosInfoBean.RecordsBean item) {
        return R.layout.item_posinfo_list;
    }

}
